package com.tcu.user.controller.spec;

import com.tcu.exception.SmartException;
import com.tcu.result.R;
import com.tcu.user.entity.spec.AppUser;
import com.tcu.user.service.spec.IAppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app-user")
public class AppUserController {
    private IAppUserService appUserService;

    @PostMapping("add")
    public R addInfo(@RequestBody AppUser appUser){
        if (appUser.getUid()==null) {
            throw new SmartException(20001,"用户id不能为空");
        }
        appUserService.save(appUser);
        return R.success();
    }
    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable String id){
        boolean b = appUserService.removeById(id);
        return b ? R.success() : R.error();
    }
    @PostMapping("update")
    public R update(@RequestBody AppUser appUser){
        if (appUser.getUid()==null) {
            throw new SmartException(20001,"用户id不能为空");
        }
        boolean b = appUserService.updateById(appUser);
        return b ? R.success() : R.error();
    }
    @GetMapping("getInfo/{id}")
    public R getInfo(@PathVariable String id){
        AppUser byId = appUserService.getById(id);
        return R.success().data("appUserInfo", byId);
    }

    @Autowired
    public void setAppUserService(IAppUserService appUserService) {
        this.appUserService = appUserService;
    }
}
